package com.jin.flashsaled.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jin.flashsaled.entity.Goods;
import com.jin.flashsaled.mapper.GoodsMapper;
import com.jin.flashsaled.result.Good;
import com.jin.flashsaled.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 靳鹏宇
 * @since 2025-09-18
 */
@Service
@Slf4j
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public List<Good> getGoodsAllWithDetail() {
        List<Good> goodsList = goodsMapper.selectGoodsWithSeckill(null);
        return goodsList;
    }

    @Override
    public Good getGoodsWithDetailById(Long id) {
        //使用下面的由于是继承，aql语句写的左连接，会导致不知道id是那个表的id
        //LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
        //queryWrapper.eq(Goods::getId, id);
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("g.id",id);   // 手动指明 g.id
        List<Good> good = goodsMapper.selectGoodsWithSeckill(queryWrapper);
        Good resultGood=good.get(0);
        return resultGood;
    }
}
